package com.xjrsoft.common.converter;

import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.ITypeConvert;
import com.baomidou.mybatisplus.generator.config.converts.SqlServerTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;

import static com.baomidou.mybatisplus.generator.config.rules.DbColumnType.*;
import static com.xjrsoft.common.converter.XjrTypeConverts.contains;
import static com.xjrsoft.common.converter.XjrTypeConverts.containsAny;

public class XjrSqlServerTypeConvert implements ITypeConvert {
    public static final SqlServerTypeConvert INSTANCE = new SqlServerTypeConvert();

    @Override
    public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
        return XjrTypeConverts.use(fieldType)
                .test(containsAny("char", "xml", "text").then(STRING))
                .test(contains("bigint").then(LONG))
                .test(contains("int").then(INTEGER))
                .test(containsAny("date", "time", "datetime").then(LOCAL_DATE_TIME))
                .test(contains("bit").then(BOOLEAN))
                .test(containsAny("decimal", "numeric").then(DOUBLE))
                .test(contains("money").then(BIG_DECIMAL))
                .test(containsAny("binary", "image").then(BYTE_ARRAY))
                .test(containsAny("float", "real").then(FLOAT))
                .test(contains("double").then(DOUBLE))
                .or(STRING);
    }
}
